package utils.config;


import java.util.*;
import java.io.*;


public class Config implements Serializable  {
	
	private Map<String,Object> config;
	
	Config() {
		config = new HashMap<String,Object>();
	}
	
	public Config(String file) {
		try {
		ObjectInputStream oin = new ObjectInputStream(new BufferedInputStream(new FileInputStream(new File(file))));
		config = (Map<String,Object>)oin.readObject();
		oin.close();
		} catch(Exception e) {
			e.printStackTrace();
		}
	}
	
	void save(String file) {
		try {
			ObjectOutputStream oout = new ObjectOutputStream(new BufferedOutputStream(new FileOutputStream(new File(file))));
			oout.writeObject(config);
			oout.close();
		} catch(Exception e) {
			e.printStackTrace();
		}
	}
	
	public Object get(String key) {
		return config.get(key);
	}
	public void put(String key, Object o) {
		config.put(key, o);
	}
	public String toString() {
		StringBuffer sb = new StringBuffer();
		for(String key: config.keySet())
			sb.append(key+" = "+config.get(key)+"\n");
		return sb.toString();
	}	
}
